float calibrateSensor(int pin) {
  float total = 0;

  for (int i = 0; i < 20; ++i) {
    total += analogRead(pin);
    delay(20);
  }

  return total / 20;
}

int readAverageAnalog(int pin, int samples, boolean pause) {
  float total = 0;

  for (int i = 0; i < samples; ++i) {
    total += analogRead(pin);
    if (pause) {
      delay(1);
    }
  }

  return total / samples;
}

